package enemy;

import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.ArrayList;

import bullets.BulletBoss;
import bullets.BulletEnemy;
import core.Boom;
import core.World;



public class EnemyBoss extends Enemy implements Score,Reward{
	/**
	 * 
	 */
	private static final long serialVersionUID = -1666805580513693956L;
	public static BufferedImage image;
	private int bossScore=10;
	static {
		image = readImage("src/images/boss1.png");
	}
	private int speedX;//横向速度
	private int now;//BOSS的出场状态
	
	public EnemyBoss(int spx) {
		super(574, 376, spx, 100);//BOSS机的宽高，纵向速度和生命值
		speedX = spx;
		now = 0;
	}
	public BufferedImage getImage() {
		if(isLife()) {
			return image;
		}
		return null;
	}
	public void step() {
		/*
		 * boss出场时的y是小于0的，如果不加状态now的话，
		 * 一出来就判断y<=0的话，那么boss就会一直卡在边缘的上端
		 * 所以等boss出场后，当它的y超过了0，那么就可以更改状态
		 * now为1，这样就可以当boss会退到边缘时还可以再往前走.
		 */
		if(y>=World.WORLD_HEIGHT/8) {
			now = 1;//改变状态				
			speed*=-1;			
		}
		if(y<=0 && now == 1) {
			speed*=-1;
		}
		if(x<=0 || x>=World.WORLD_WIDTH-this.width) {
			speedX*=-1;
		}
		this.y+=speed;
		this.x+=speedX;	
	}
	@Override
	public BulletEnemy enemyShoot() {
		// TODO Auto-generated method stub
		return null;
	}
	public ArrayList<BulletBoss> enemyBossShoot() {
		ArrayList<BulletBoss> abb = new ArrayList<BulletBoss>();
		//boss的第一种攻击方式，三发子弹
		//三颗子弹的出场位置一样，但是会向不同的方向移动
		abb.add(new BulletBoss(this.x+30,this.y+this.height));
		abb.add(new BulletBoss(this.x+this.width/2,this.y+this.height));
		abb.add(new BulletBoss(this.x+480,this.y+this.height));
		return abb;
	}	
	@Override
	public void paintImage(Graphics g) {		
		if(status==live) {
			g.drawString("BOSS生命值="+getLife(), 20, 140);
			g.drawImage(image, x, y,null);
		}
		if(status==dead) {
			g.drawImage(Boom.image[index-1], x, y,null);
		}		
	}
	@Override
	public int getRewaqrdType() {	
		return ADD_LIFE;
	}
	@Override
	public int getScore() {
		return bossScore;
	}
}
